import { Transform } from "class-transformer";
import { IsBoolean, IsBooleanString, IsNotEmpty, IsNumber, IsString } from "class-validator";
import { BaseEntity } from "src/baseEntity";
import { Dept } from "src/dept/dept.entity";
import { System } from "src/system/system.entity";
import { Column, Entity, ManyToOne } from "typeorm";



@Entity("cnannel")
export class Channel extends BaseEntity {
    @ManyToOne(() => System)
    system: System

    @ManyToOne(() => Dept)
    dept: Dept

    @Column()
    @IsNotEmpty({ message: '姓名不能为空' })
    @IsString({ message: '姓名必须是字符串' })
    name: string;


    @Column()
    @IsNotEmpty({ message: '性别不能为空' })
    @Transform(({ value }) => value === 'true')
    gender: boolean;

    @Column()
    @IsNotEmpty({ message: '岗位不能为空' })
    @IsString({ message: '岗位必须是字符串' })
    position: string;

    @Column()
    @IsNotEmpty({ message: '年龄不能为空' })
    @IsNumber({}, { message: '年龄必须是数字' })
    @Transform(({ value }) => parseInt(value)) // 将输入转换为数字类型
    age: number;

    @Column()
    @IsNotEmpty({ message: '电话不能为空' })
    phone: string;

    @Column()
    @IsNotEmpty({ message: '所属单位不能为空' })
    @IsString({ message: '所属单位必须是字符串' })
    organization: string;

    @Column()
    @IsString({ message: '批注必须是字符串' })
    comment: string;
}